<template>
  <li :class="{checked:checked}">
    <label>
      <!--v-model脏数据的问题-->
      <!--<input type="checkbox" v-model="task.checked"/>-->
      <!--<input type="checkbox" :checked="task.checked" @change="checkedC(task.id,$event)"/>-->
      <input type="checkbox" v-model="checked"/>
      <span>{{task.content}}</span>
    </label>
    <button class="btn btn-danger" @click="delTask(task.id)">删除</button>
  </li>
</template>

<script>
  export default {
    name: "v-item",
    props:["task"],
    computed:{
      checked:{
        get(){return this.task.checked},
        set(checked){
          //checked: 最新的值!!!!
          this.$bus.$emit("checkedC",{id:this.task.id,checked})
        }
      }
    },
    methods:{
      //删除指定任务
      delTask(id){
        this.$bus.$emit("delTask",id)
      },
      //选中状态切换
      checkedC(id,ev){
        //id: 当前点击的是哪个复选框
        //checked:当前点击的复选框的最新状态
        let checked = ev.target.checked;
        this.$bus.$emit("checkedC",{id,checked})
      }
    }
  }
</script>

<style scoped>
  /*damu add*/
  li:hover{
    background: pink;
  }
  li button{
    display: none;
  }
  li:hover button{
    display: block;
  }

  li{position: relative}
  li.checked:after{
    content: "";
    display: block;
    height: 3px;
    width: 70%;
    background: red;

    position: absolute;
    left: -125px;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
  }
  /*damu add*/


  li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
  }

  li label {
    float: left;
    cursor: pointer;
  }

  li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
  }

  li button {
    float: right;
    margin-top: 3px;
  }

  li:before {
    content: initial;
  }

  li:last-child {
    border-bottom: none;
  }
</style>